package Template::Plugin::Filter::Pipe;

use strict;
use warnings;
use Text::Pipe;


our $VERSION = '0.02';


use base qw(Template::Plugin::Filter);


sub init {
    my $self = shift;
    $self->{_DYNAMIC} = 1;
    $self->install_filter($self->{_ARGS}[0] || 'pipe');
    $self;
}


sub filter {
    my ($self, $text, $args, $config) = @_;

    die "pipe name?\n" unless defined $args->[0];
    my $pipe = Text::Pipe->new($args->[0], %$config);
    $pipe->filter($text);
}



1;


__END__

{% USE p = PodGenerated %}

=head1 NAME

{% p.package %} - Filter plugin adapter for Text::Pipe

=head1 SYNOPSIS

    [%- USE Filter.Pipe -%]
    [%- 'a test' | pipe("Uppercase") |
        pipe("Repeat", times => 2, join => " = ") |
        pipe("Reverse") -%]
    EOTMPL

=head1 DESCRIPTION

This Template Toolkit filter plugin is an adapter for L<Text::Pipe>. The
default filter name is C<pipe>, but you can override this with the C<USE>
directive.

When using the filter, you need to pass the name of the pipe segment you would
like to create, and optionally named arguments to be passed to the pipe.

See L<Text::Pipe> and its derived distributions for more detail on which pipe
segments are available and which arguments they take.

=head1 METHODS

=over 4

{% p.write_methods %}

=item init

Overrided method - see L<Template::Plugin::Filter> for details.

=item filter

Overrided method - see L<Template::Plugin::Filter> for details.

=back

{% p.write_inheritance %}

{% PROCESS standard_pod %}

=cut

